<!--内容开始-->
<script src="<?php echo Url::base(); ?>js/jquery.min.js"></script>
<script src="<?php echo Url::base(); ?>jquery.uploadify.min.js" type="text/javascript"></script>
<script src="<?php echo Url::base(); ?>js/jquery.Jcrop.js"></script>

<script type="text/javascript">

    jQuery(function($){



    });

    // Simple event handler, called from onChange and onSelect
    // event handlers, as per the Jcrop invocation above
    function showCoords(c)
    {
        $('#x1').val(c.x);
        $('#y1').val(c.y);

        $('#w').val(c.w);
        $('#h').val(c.h);
    };

    function clearCoords()
    {
        $('#coords input').val('');
    };



</script>

<div class="personal w1200">

    <div class="personal-r f-r">
        <div class="personal-right">
            <div class="personal-r-tit">
                <h3>个人资料</h3>
            </div>

            <div class="data-con">

                <div class="dt1">
                  
                    <!-- This is the image we're attaching Jcrop to -->
                    <!-- This is the form that our event handler fills -->


                    <div class="touxiang f-l">

                        <div style="clear:both;"></div>
                    </div>
                    <div style="clear:both;"></div>
                </div>

<style>
    #file_upload-queue{
        display: none;
    }
    .uploadify-button {
        margin-left: 180;
        margin-top: -70;
        color: #63A61D;
    }

    .jcrop-holder{margin-left: 96;}
</style>

<form method="post" id="form1" name="form1" action=""> </form>

                <div class="dt1">
                    <div id="uploadimg">
                    <p class="dt-p f-l">头像：</p>
                    <div class="tu f-l">
                        <?php
                        $photo = 'images/data-tu.gif';
                        if(isset($user['img'])&&$user['img'] !=''){
                            $photo = '/uploads/'.$user['img'];
                        }
                        ?>
                        <a href="#">
                            <img src="<?php echo Url::base().$photo; ?>" width="80" height="80" />

                        </a>
                    </div>


                        <input id="file_upload" name="name" type="file" multiple="true">
                    </div>
                    <p class="dt-p f-l" id="chose" style="display:none;">剪切头像：</p>
                    <div id="corp" style="display: none;">

                    <img  id="photo"  src="<?php echo Url::base(); ?>images/sago.jpg" id="target" alt="[Jcrop Example]" />
                      <form id="coords"
                          class="coords"
                          onsubmit="return false;"
                          action="http://example.com/post.php">

                        <div class="inline-labels">
                            <label> <input type="hidden" size="4" id="x1" name="x1" /></label>
                            <label> <input type="hidden" size="4" id="y1" name="y1" /></label>
                            <label> <input type="hidden" size="4" id="w" name="w" /></label>
                            <label> <input type="hidden" size="4" id="h" name="h" /></label>
                            <input type="button" style="width: 100;background-color: #63A61D;margin-left: 95px;" value="保存" onclick="save()" width="100"/>
                        </div>
                    </form>
                    <script type="text/javascript">
                        var fileUrl = "";
                        function save(){
                            console.log(11)
                            console.log( {w:$('#w').val(),h:$("#h").val(),x1:$('#x1').val(),y1:$("#y1").val(),file:fileUrl});
                            $.ajax({

                                type: 'post',

                                url:  '<?php echo Url::base(); ?>index.php/user/corpImg',

                                data: {w:$('#w').val(),h:$("#h").val(),x1:$('#x1').val(),y1:$("#y1").val(),file:fileUrl} ,

                                success: function(data){
                                    console.log(data)
//alert(data['msg'])
                                    if(data['msg']==1){
                                        alert("保存成功");
                                    }else if(data['msg']== -1){
                                        alert("未登录")
                                    }else{
                                        alert("系统异常稍后重试")
                                    }
                                    window.location.reload()
                                },

                                dataType: 'json'

                            });
                        }
                    </script>
                    </div>
                    <div style="clear:both;">




                    </div>
                </div>
                <script type="text/javascript">
                    var url = null;
                    <?php $timestamp = time();?>
                    $(function() {


                        $('#file_upload').uploadify({
                            buttonClass: "sc f-l",

                            'swf'      : '<?php echo Url::base(); ?>uploadify.swf',
                            'uploader' : '<?php echo Url::base(); ?>index.php/productm/upload',
                            'onUploadSuccess':function(file,data,response){
                                if(data== 'false'){
                                    alert("图片格式不正确请检查")
                                }else{

                                    $("#chose").show()
                                    file = (data+"").replace("\"","").replace("\"","");
                                    console.log((data+"").replace("\"","").replace("\"",""))
                                    fileUrl =(data+"").replace("\"","").replace("\"","");
                                    console.log("<?php echo Url::base(); ?>/temp/"+fileUrl)
                                    $("#photo").attr("src","<?php echo Url::base(); ?>/temp/"+fileUrl);
                                    $("#uploadimg").hide();
                                    var jcrop_api;

        $('#photo').Jcrop({
            minSize: [48,48],
            maxSize:[300,300],
            setSelect: [0,0,190,190],
            onChange:   showCoords,
            onSelect:   showCoords,
            onRelease:  clearCoords
        },function(){
            jcrop_api = this;
        });


                                   document.getElementById('corp').style.display='block'
                                }
                            }
                        });
                    });
                </script>
                <div class="dt1">
                    <p class="dt-p f-l">昵称：</p>
                    <input type="text" name="username" value="<?php echo $user['username']; ?>" readonly placeholder="RH了" />
                    <div style="clear:both;"></div>
                </div>
                 <div class="dt1">
                    <p class="dt-p f-l">昵称：</p>
                    <input type="text"  value="<?php echo $user['email']; ?>" readonly placeholder="邮箱" />
                    <div style="clear:both;"></div>
                </div>
                <div class="dt1 dt2">
                    <p class="dt-p f-l">性别：</p>
                    <input type="radio" name="sex" <?php if($user['sex'] =='男'){ echo 'checked';} ?>  value="男"></input><span>男</span>
                    <input type="radio" name="sex"   <?php if($user['sex'] =='女'){ echo 'checked';} ?>   value="女"></input><span>女</span>
                    <div style="clear:both;"></div>
                </div>
                <div class="dt1">
                    <p class="dt-p f-l">年龄：</p>
                    <input type="number" value="<?php echo $user['age']; ?>" name="age"  />
                    <div style="clear:both;"></div>
                </div>
                <div class="dt1">
                    <p class="dt-p f-l">手机号：</p>
                    <input type="text"   readonly value="<?php echo $user['phone']; ?>"  />
                    <div style="clear:both;"></div>
                </div>
                <div class="dt1 dt3">
                    <p class="dt-p f-l">修改手机：</p>
                    <input type="text" id="phone" onblur="checkPhone()" value=""   />
                    <button id="send" onclick="sendPhoneMsg()">获取短信验证码</button>
                    <div style="clear:both;"></div>
                </div>
                <div class="dt1">
                    <p class="dt-p f-l">验证码：</p>
                    <input type="text" value="" name="phoneCode" id="phoneCode" />
                    <div style="clear:both;" ></div>
                </div>
                <div class="dt1">
                    <p class="dt-p f-l">邮箱：</p>
                    <input type="text" id="email" name="email" value="<?php echo $user['email']; ?>" />
                    <div style="clear:both;"></div>
                </div>
                <div class="dt1 dt3">
                    <p class="dt-p f-l">验证码：</p>
                    <input type="text" value=""  name="emailCode" id="emailCode" />
                    <button id="sendEmail" onclick="sendEmail()">发送邮箱验证码</button>
                    <div style="clear:both;"></div>
                </div>
                <button class="btn-pst" onclick="saveMethod()">保存</button>
            </div>
        </div>
    </div>
    <div style="clear:both;"></div>
</div>
<script type="text/javascript">
var save = true;
function saveMethod(){
    var url = "<?php echo Url::base(); ?>index.php/user/modfiyPersonal";
    if(save){
            save=false;
            if($("#phoneCode").val()==""){
                save=true;
                alert("手机验证码不能为空")
                return false;
            }

            if($("#emailCode").val()==""){
                save=true;
                alert("邮箱验证码不能为空")
                return false;
            }
            var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

            if($("#email").val()==""||!filter.test($("#email").val()))
            {
                save=true;
                alert('请输入正确邮箱');
                return;
            }
            if($("#phone").val()==""||!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test($("#phone").val()))
            {
                save=true;
                alert('请输入正确手机号');
                return;
            }
        console.log({age:$("#age").val()||"",sex:$("#sex").val()||"",email:$("#email").val(),phone:$("#phone").val(),phoneCode:$("#phoneCode").val(),emailCode:$("#emailCode").val()} )
            $.ajax({

            type: 'post',

            url:  url,

            data: {age:$("#age").val(),sex:$("#sex").val(),email:$("#email").val(),phone:$("#phone").val(),phoneCode:$("#phoneCode").val(),emailCode:$("#emailCode").val()} ,

            success: function(data){
                save = true;
                console.log(22)
                if(data.msg ){
                    window.location.reload()
                }else{
                    if(data.data == '未登录'){
                        window.location.href=url+'index.php/login/login'
                    }else {

                        alert(data.data)
                    }
                }
            },
                error:function(){save=true;},

            dataType: 'json'

        });
    }
}
    var count = 60;
var timename = null;
    var url = '<?php echo Url::base(); ?>';
var control  = true;
var sendBindEmail  = true;
  function checkPhone(){


    }
function sendEmail(){
        if(sendBindEmail){
            sendBindEmail=false;
            var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

            if($("#email").val()==""||!filter.test($("#email").val()))
            {
                sendBindEmail=true;
                alert('请输入正确邮箱');
                return;
            }

            $.ajax({

                type: 'get',

                url:  url+'index.php/user/sendBindEmail',

                data: {email:$("#email").val()} ,

                success: function(data){
                    sendBindEmail= true;
                    if(data.msg ){
                        timename=setInterval(function() {
                            if(count == 0){
                                count = 60;
                                sendBindEmail= true;
                                $("#sendEmail").html("获取短信验证码")

                                clearInterval(timename)
                                return;
                            }
                           $("#sendEmail").html(count+"后重新发送")

                            count --;
                        },1000);
                    }else{
                        sendBindEmail= true;
                        if(data.data == '未登录'){
                            window.location.href=url+'index.php/login/login'
                        }else {

                            alert(data.data)
                        }
                    }
                },

                dataType: 'json'

            });
        }
    }
    function sendPhoneMsg(){
        if(control){
            control=false;

        if($("#phone").val()==""||!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test($("#phone").val()))
        {
            control=true;
            alert('请输入正确手机号');
            return;
        }

        $.ajax({

            type: 'get',

            url:  url+'index.php/user/sendBindPhone',

            data: {phone:$("#phone").val()} ,

            success: function(data){
                if(data.msg ){
                    timename=setInterval(function() {
                        if(count == 0){
                            count = 60;
                            control= true;
                            $("#send").html("获取短信验证码")

                            clearInterval(timename)
                            return;
                        }
                       $("#send").html(count+"后重新发送")

                        count --;
                    },1000);
                }else{
                    control= true;
                    if(data.data == '未登录'){
                        window.location.href=url+'index.php/login/login'
                    }else {

                        alert(data.data)
                    }
                }
            },

            dataType: 'json'

        });
        }
    }

</script>